import { Component, OnInit } from '@angular/core';
//导入
import { ActivatedRoute, Params } from '@angular/router'

declare var $: any;

//Http 类
import { Http } from '@angular/http';
//可以把http请求转化成promise
import 'rxjs/add/operator/toPromise'

@Component({
  selector: 'app-edit',
  templateUrl: './edit.component.html',
  styleUrls: ['./edit.component.css']
})
export class EditComponent implements OnInit {
  result={}
  // student = {};
  constructor(private http: Http, private route: ActivatedRoute) { }

  ngOnInit() {
    this.route.params.subscribe((params: Params) => {
      console.log(params.id)
      $.get('http://192.168.40.205/h25/api/one.php', {id:params.id})
        .done((res) => {
          console.log(res)
          this.result = res.data
        })
    })
  }

  //修改函数
  xiuClick(result) {
    console.log(result)
    $.post('http://192.168.40.205/h25/api/update.php', result)
    .done((res) => {
        	console.log(res)
          this.result = res.data
        	alert(res.message)
          location.href = "list"
        })
  }

}
